package map;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * forEach遍历集合
 *
 */

public class ForEachDemo {
    public static void main(String[] args) {
        Map<String,Integer>map = new HashMap<>();
        map.put("语文",99);
        map.put("数学",98);
        map.put("英语",88);
        map.put("物理",80);
        map.put("化学",99);
        System.out.println(map);//{物理=80, 数学=98, 化学=99, 语文=99, 英语=88}

        Set<String>keset = map.keySet();//获取所有健
        keset.forEach(s-> System.out.println(s));

        Collection<Integer>values = map.values();
        values.forEach(v-> System.out.println("value:"+v));

        Set<Map.Entry<String,Integer>>entrySet = map.entrySet();
        entrySet.forEach(e->System.out.println("key:"+e.getKey()+",value:"+e.getValue()));

       map.forEach((k,v)-> System.out.println("k:"+k));
       map.forEach((k,v)-> System.out.println("v:"+v));
       map.forEach((k,v)-> System.out.println("k:"+k+"v:"+v));



    }
}
